<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if(!class_exists('CI_Model')) { class CI_Model extends Model {} }

class Slider_model extends CI_Model {
	var $perpage = 10;
	var $url;
	public function __construct() {
	   parent::__construct();
	   $this->url = $this->uri->segment(1);
	}
	public function all($id, $cat) {
		if(!$id){
			$data['brands'] = $this->db->select()->from('catalog_brands')->where('brand_status',1)->where("brand_image != ''")->where('brand_main', 1)->order_by('brand_order', 'asc')->get()->result_array();
		} else {
			if($cat == 'hit'){
				$parents = array();
				$parents[] = $id;
				$chs = $this->db->select()->from('catalog_parents')->where('parent_parent',$id)->get()->result_array();
				foreach($chs as $ch){
					$parents[] = $ch['parent_id'];
				}
				$data['items'] = array();
				$data['items'] = $this->db->select()->from('catalog_items')->where_in('item_parent',$parents)->where('item_hit',1)->where('item_status',1)->order_by('item_order', 'asc')->get()->result_array();
				if(count($data['items']) > 0){
					foreach($data['items'] as $key=>$item){
						$image= $this->db->select()->from('catalog_images')->where('photo_item',$item['item_id'])->where('photo_main',1)->limit(1)->get()->row_array();
						if(count($image) <= 0){
							$image= $this->db->select()->from('catalog_images')->where('photo_item',$item['item_id'])->limit(1)->get()->row_array();
						}
						$data['items'][$key]['image'] = $image;
					}
				}
			}
		}
		return $this->load->view('modules/slider/index', $data, true);
	}
}